import scrapy
import json


class TestpostSpider(scrapy.Spider):
    name = "testpost"
    allowed_domains = ["fanyi.baidu.com"]



    def start_requests(self):
        url = 'https://fanyi.baidu.com/sug'
        data = {'kw': 'final'}
        yield scrapy.FormRequest(url=url, formdata=data, callback=self.parse_second)

    def parse_second(self, response):
        try:
            # 直接使用response.text（已经是字符串）
            obj = json.loads(response.text)
            print("解析结果:", obj)



        except json.JSONDecodeError as e:
            print("JSON解析失败:", e)
            print("响应内容:", response.text)